package proxy_pattern.remote.ex2;

import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 * @author 申书航
 * @version 1.0
 * 服务端类，用于创建并绑定远程对象的RMI注册服务
 */
public class Serve {

    /**
     * 主方法，程序入口，负责创建远程对象并将其注册到RMI注册表
     * @param args 命令行参数
     */
    public static void main(String[] args) {
        //创建Remote Object
        MyBase64 remote = new MyBase64();
        IBase64 stub = null;
        try {
            stub = (IBase64) UnicastRemoteObject.exportObject(remote, 0);
            //创建注册服务
            Registry registry = LocateRegistry.createRegistry(3000);
            //在注册服务中绑定Remote Object
            registry.bind("base64", stub);
            System.err.println("Server Ready");
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        } catch (AlreadyBoundException e) {
            throw new RuntimeException(e);
        }

    }
}
